#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include <sys/types.h>

int g_uval;
int g_val = 100;

int main(int argc,char* argv[],char*env[])
{
	//观察一个奇怪的现象：
	pid_t id = fork();
	if(id == 0)
	{
		//子进程执行
		int cnt = 0;
		while(1)
		{
			printf("child process:\npid:%d\nppid%d\ng_val:%d\n&g_val:%p\n",getpid(),getppid(),g_val,&g_val);
			sleep(2);
			cnt++;
			if(cnt == 5)
			{
				g_val = 200;
				printf("child change g_val:100->200\n");
			}


		}
	}
	else
	{
		//父进程执行
		while(1)
		{
			printf("father process:\npid:%d\nppid:%d\ng_val:%d\n&g_val:%p\n",getpid(),getppid(),g_val,&g_val);
			sleep(2);
		}
	}

	//for(int i = 0;argv[i];i++)
	//{
	//	printf("argv[%d]:%p\n",i,&argv[i]);
	//}
	//for(int i =0;env[i];i++)
	//{
	//	printf("env[%d]:%p\n",i,env+i);
	//}

	return 0;
}
//	printf("代码段地址：%p\n",main);
//	printf("初始化变量的地址:%p\n",&g_val);
//	printf("未初始化变量的地址：%p\n",&g_uval);
//	char* heap = (char*)malloc(20);
//	printf("heap addr：%p\n",heap);
//	printf("栈上的地址：%p\n",&heap);

